package com.yishe.controller.recharge;

import com.yishe.biz.wx.recharge.RechargeBiz;
import com.yishe.config.ObjectRestResponse;
import com.yishe.entites.mysql.RechargeDiscountInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author : chusifeng
 * @version :
 * @date :Create in 2021/4/23 14:39
 * @description: 充值套餐
 * @package com.yishe.controller.wx.recharge
 * @className RechargeController
 */
@RestController
@RequestMapping("/recharge")
@Slf4j
public class RechargeController {

    @Resource
    private RechargeBiz rechargeBiz;

    @GetMapping(value = "getDisCounts")
    public ObjectRestResponse getDisCounts(@RequestParam("account")String account){
        ObjectRestResponse restResponse = new ObjectRestResponse();
        try {
            restResponse.setData(rechargeBiz.getDisCounts(account));
        } catch (Exception e) {
            log.error("查询失败！",e);
        }
        return restResponse;
    }

    /**
     * 保存优惠套餐
     * @param discountInfo
     * @return
     */
    @PostMapping(value = "saveDis")
    public ObjectRestResponse saveDis(@RequestBody RechargeDiscountInfo discountInfo){
        ObjectRestResponse restResponse = new ObjectRestResponse();
        try {
            rechargeBiz.saveDis(discountInfo);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("修改失败",e);
            restResponse.setErrorMsg("修改失败");
        }
        return restResponse;
    }
}
